package com.balance.anole.erp.report.action;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;

import org.eclipse.jface.action.Action;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;

import com.balance.anole.erp.constant.IIcons;

public class ReportDemoPdfAction extends Action{
	
	public void setEnabled(boolean enabled){
		super.setEnabled(enabled);
		if(enabled){
			setImageDescriptor(com.balance.anole.erp.Activator.getImageDescriptor(IIcons.SAVE));		
		}else{
			setImageDescriptor(com.balance.anole.erp.Activator.getImageDescriptor(IIcons.DISABLE_SAVE));
		}
	}
	
	public ReportDemoPdfAction(){
		setToolTipText("transfer PDF");		
	}
	
	public void run(){
		try {		
			String fileName = "ReportDemo.pdf";
			FileDialog fileDlg = new FileDialog(Display.getCurrent().getActiveShell(),SWT.SAVE);
			fileDlg.setFileName(fileName);		
			fileName = fileDlg.open();
			
			if(fileName!=null){
				JasperExportManager.exportReportToPdfFile("C:\\Documents and Settings\\zhouxiaobo\\workspace\\Anole-client\\report\\report1.jrprint",fileName);
			}			
		} catch (JRException e) {
			e.printStackTrace();
		}
	}
}
